package com.ling.feign.plus.gson;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.ling.feign.plus.model.BusinessExceptionModel;

import java.io.IOException;

public class BusinessExceptionModelTypeAdapter extends TypeAdapter<BusinessExceptionModel> {
    @Override
    public void write(JsonWriter out, BusinessExceptionModel value) throws IOException {

    }

    @Override
    public BusinessExceptionModel read(JsonReader jsonReader) throws IOException {
        Gson gson = new GsonBuilder()
                .registerTypeAdapter(String.class, new StringTypeAdapter())
                .registerTypeAdapter(Integer.class, new IntegerTypeAdapter())
                .registerTypeAdapter(StackTraceElement.class, new StackTraceElementTypeAdapter())
                .create();
        return gson.fromJson(jsonReader.nextString(), BusinessExceptionModel.class);
    }
}
